/****** Object:  Stored Procedure dbo.CGO_TriviaGetResultSummary    Script Date: Monday, March 07, 2011 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'dbo.CGO_TriviaGetResultSummary') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure dbo.CGO_TriviaGetResultSummary
GO

/* -------------------------------------------------------------------------------------
/   AccountGet
/  ------------------------------------------------------------------------------------- */
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE dbo.CGO_TriviaGetResultSummary	
  @EnrollID INT,
  @UserID INT
AS
  IF NOT EXISTS ( SELECT  1
                  FROM    dbo.CGO_GameEnrollment M
                          INNER JOIN dbo.CGO_GameEnrollmentStatus S ON M.EnrollStatusID = S.StatusID
                  WHERE   EnrollmentID = @EnrollID
                          AND UserID = @UserID
                )    
  BEGIN
    RETURN
  END
  
  DECLARE @CNT_Total INT
  DECLARE @CNT_Correct INT
  DECLARE @CNT_Wrong INT
  DECLARE @CNT_Uncompleted INT
  DECLARE @CNT_Deprecated INT
  
  SELECT  @CNT_Total = COUNT(*)
  FROM    dbo.CGO_TriviaResult
  WHERE   GameEnrollmentID = @EnrollID
  
  SELECT  @CNT_Correct = COUNT(*)
  FROM    dbo.CGO_TriviaResult
  WHERE   GameEnrollmentID = @EnrollID
          AND ResultStatusID = 2
          AND Correct = 1
  
  SELECT  @CNT_Wrong = COUNT(*)
  FROM    dbo.CGO_TriviaResult
  WHERE   GameEnrollmentID = @EnrollID
          AND ResultStatusID = 2
          AND Correct = 0
          
  SELECT  @CNT_Uncompleted = COUNT(*)
  FROM    dbo.CGO_TriviaResult
  WHERE   GameEnrollmentID = @EnrollID
          AND ResultStatusID = 1          
          
  SELECT  @CNT_Deprecated = COUNT(*)
  FROM    dbo.CGO_TriviaResult
  WHERE   GameEnrollmentID = @EnrollID
          AND ResultStatusID = 3                 
  
  SELECT  @EnrollID AS GameEnrollmentID,
          @UserID AS UserID,
          @CNT_Total AS TotalCount ,
          @CNT_Correct AS CorrectCount ,
          @CNT_Wrong AS WrongCount ,
          @CNT_Uncompleted AS UndoCount,
          @CNT_Deprecated AS DeprecatedCount
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO